package view.rules;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import net.miginfocom.swing.MigLayout;

public class PrefixPanel extends JPanel{
	
	private JPanel prefixPanel;
	private JPanel suffixPanel;
	
	public JRadioButton affixDnChange;
	public JRadioButton endAffixChange;
	public JRadioButton enAffixChange;
	private ButtonGroup prefixButtonGroup;
	
	public JRadioButton suffixDnChange;
	public JRadioButton endSuffixChange;
	public JRadioButton enSuffixChange;
	private ButtonGroup suffixButtonGroup;
	
	
	private ButtonGroup buttonGroup2;
	
	private JCheckBox redupChekBox;
	private JLabel redupLabel;
	private JCheckBox eperChekBox;
	private JLabel eperLabel;
	private JPanel lowerPanel;
	private JRadioButton phoneRButton;
	private JRadioButton alphaRButton;
	private JButton phoneButton;
	private JPanel panel;
	private JPanel exPanel;
	
	boolean prefix;
	boolean suffix;
	boolean infixPrefix;
	boolean infixSuffix;
	
	public PrefixPanel(){
		this.setLayout(new MigLayout());
		this.setBorder(BorderFactory.createTitledBorder("Prefix"));
		
		initComponent();
		addComponent();
	}

	private void initComponent() {
		
		exPanel = new JPanel();
		exPanel.setLayout(new MigLayout());
		
		prefixPanel = new JPanel();
		prefixPanel.setLayout(new MigLayout());
		
		affixDnChange = new JRadioButton("Prefix doesn't Change");
		endAffixChange = new JRadioButton("End of Prefix Changes");
		enAffixChange = new JRadioButton("Entire Prefix Changes");
		
		prefixButtonGroup = new ButtonGroup();
		prefixButtonGroup.add(affixDnChange);
		prefixButtonGroup.add(endAffixChange);
		prefixButtonGroup.add(enAffixChange);
		
		prefixPanel.add(affixDnChange);
		prefixPanel.add(endAffixChange);
		prefixPanel.add(enAffixChange);
		prefix = true;
		
		suffixPanel = new JPanel();
		suffixPanel.setLayout(new MigLayout());
		
		suffixDnChange = new JRadioButton("Suffix doesn't Change");
		endSuffixChange = new JRadioButton("End of Suffix");
		enSuffixChange = new JRadioButton("Entire Suffix Change");
		
		suffixButtonGroup  = new ButtonGroup();
		suffixButtonGroup.add(suffixDnChange);
		suffixButtonGroup.add(suffixDnChange);
		suffixButtonGroup.add(suffixDnChange);
		
		suffix = false;
		infixPrefix = false;
		infixSuffix = false;
		
		panel = new JPanel();
		panel.setLayout(new MigLayout());
		redupChekBox = new JCheckBox();
		redupLabel = new JLabel("Reduplication");
		eperChekBox = new JCheckBox();
		eperLabel = new JLabel("Eperthesis");
		panel.add(redupChekBox);
		panel.add(redupLabel, "wrap");
		panel.add(eperChekBox);
		panel.add(eperLabel);
		
		lowerPanel = new JPanel();
		lowerPanel.setLayout(new MigLayout());
		lowerPanel.setBorder(BorderFactory.createTitledBorder(""));
		phoneRButton = new JRadioButton("Specify with Phonetic Features");
		alphaRButton = new JRadioButton("Specify with Alphabetic Characters");
		phoneButton = new JButton("Phonetic Features");
		
		buttonGroup2 = new ButtonGroup();
		buttonGroup2.add(phoneRButton);
		buttonGroup2.add(alphaRButton);
		
	}

	private void addComponent() {
		
		addToPrefixPanel();
		exPanel.add(prefixPanel, "wrap");
		add(exPanel, "wrap");
		addToLowerPanel();
		add(lowerPanel);
		add(panel);
		
	}
	
	private void addToPrefixPanel(){
		prefixPanel.add(affixDnChange);
		prefixPanel.add(endAffixChange);
		prefixPanel.add(enAffixChange);
	}
	
	private void addToLowerPanel(){
		lowerPanel.add(phoneRButton);
		lowerPanel.add(phoneButton, "wrap");
		lowerPanel.add(alphaRButton);
	}
	
	public void setPanel(String affix){
		
		if (affix == "prefix" && prefix == false){
			affixDnChange.setText("Prefix doesn't Change");
			endAffixChange.setText("End of Prefix Change");
			enAffixChange.setText("Entire Preffix Change");
            prefix = true;
            suffix = false;
            

    		this.setBorder(BorderFactory.createTitledBorder("Prefix"));

		}
		
		if (affix == "suffix" && suffix == false){
			affixDnChange.setText("Suffix doesn't Change");
			endAffixChange.setText("Beginning of Suffix Change");
			enAffixChange.setText("Entire Suffix Change");
            suffix = true;
            prefix = false;
            infixPrefix = false;
            infixSuffix = false;
            

    		this.setBorder(BorderFactory.createTitledBorder("Suffix"));

		}
		
		if (affix == "suffix" && suffix == false){
			affixDnChange.setText("Suffix doesn't Change");
			endAffixChange.setText("Beginning of Suffix Change");
			enAffixChange.setText("Entire Suffix Change");
            suffix = true;
            prefix = false;
            infixPrefix = false;
            infixSuffix = false;

    		this.setBorder(BorderFactory.createTitledBorder("Suffix"));

		}
		
		if (affix == "infixPrefix" && infixPrefix == false){
			affixDnChange.setText("Infix doesn't Change");
			endAffixChange.setText("End of Infix Change");
			enAffixChange.setText("Entire Infix Change");
            infixPrefix = true;
            prefix = false;
            suffix = false;
            infixSuffix = false;
            
            this.setBorder(BorderFactory.createTitledBorder("Suffix"));

		}
		
		if (affix == "infixSuffix" && infixSuffix == false){
			affixDnChange.setText("Infix doesn't Change");
			endAffixChange.setText("Beginning of Infix Change");
			enAffixChange.setText("Entire Infix Change");
            infixPrefix = false;
            prefix = false;
            suffix = false;
            infixSuffix = true;
            
            this.setBorder(BorderFactory.createTitledBorder("Suffix"));

		}
		
	}
		
}


